<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>vue专用测试</title>
	<script src="vue.js"></script>
</head>

<body>
	<div id="app">
		<button @click="callChildMethod()">父组件调用子组件中的方法</button>
		<child ref="child"></child>
	</div>
	<script>
		new Vue({
			el: "#app",
			components: {
				"child": {
					template: `<div>父组件调用子组件中的方法(我是子组件)</div>`,
					data() {
						return {}
					},
					methods: {
						childMethod() {
							alert("子组件被调用")
						}
					}
				}
			},
			data: {},
			methods: {
				callChildMethod() {
					console.log(this.$refs.child);
					this.$refs.child.childMethod();
				}
			}

		});
	</script>

</body>

</html>